//get param from url
function GetQueryString(str, name)
{
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)", "i");
	var r = str.match(reg);
	if (r) {
		return unescape(r[2]);
	}
	return "";
} 
//get param from url
function GetqueryStringFromUrl(name)
{
	var strUrl = location.search;
	strUrl = strUrl.replace('?','');
	if( strUrl.indexOf("#") == -1 )
	{
		return GetQueryString(strUrl, name);
	}
	return "";
}
//be userd in ps
function GetHomeIdFromUrl()
{
	return GetqueryStringFromUrl('hid');
}
function setInnerHtml(ctl,txt){
var obj=document.getElementById(ctl);
if(obj)obj.innerHTML=txt;
}
//
function XmlDom() {
  //IE or Mozilla
  if (window.ActiveXObject) {
    var arrSignatures = ["MSXML2.DOMDocument.5.0", "MSXML2.DOMDocument.4.0","MSXML2.DOMDocument.3.0", "MSXML2.DOMDocument","Microsoft.XmlDom"];
    for (var i=0; i < arrSignatures.length; i++) {
      try {
        var oXmlDom = new ActiveXObject(arrSignatures[i]);
        return oXmlDom;
      } catch (oError) {
        //ignore
      }
    }          
    throw new Error("MSXML is not installed on your system."); 
           
    //IE or Mozilla       
  } else if (document.implementation && document.implementation.createDocument) {
    var oXmlDom = document.implementation.createDocument("","",null);
    //Mozilla parseError object
    oXmlDom.parseError = {valueOf: function () { return this.errorCode; },toString: function () { return this.errorCode.toString() }};
        
    //init parseError
    Document.prototype.__initError__ = function () {
      this.parseError.errorCode = 0;
      this.parseError.filepos = -1;
      this.parseError.line = -1;
      this.parseError.linepos = -1;
      this.parseError.reason = null;
      this.parseError.srcText = null;
      this.parseError.url = null;
    };
    //init parseError object
    oXmlDom.__initError__();
                
        
    oXmlDom.addEventListener("load", function () {
      this.__checkForErrors__();
      this.__changeReadyState__(4);
    }, false);

    Document.prototype.readyState = 0;
    Document.prototype.onreadystatechange = null;

    
    Document.prototype.__changeReadyState__ = function (iReadyState) {
      this.readyState = iReadyState;

      if (typeof this.onreadystatechange == "function") {
        this.onreadystatechange();
      }
    };
   
    
    Document.prototype.__checkForErrors__ = function () {

      if (this.documentElement.tagName == "parsererror") {

        var reError = />([\s\S]*?)Location:([\s\S]*?)Line Number (\d+), Column (\d+):<sourcetext>([\s\S]*?)(?:\-*\^)/;

        reError.test(this.xml);
        
        this.parseError.errorCode = -999999;
        this.parseError.reason = RegExp.$1;
        this.parseError.url = RegExp.$2;
        this.parseError.line = parseInt(RegExp.$3);
        this.parseError.linepos = parseInt(RegExp.$4);
        this.parseError.srcText = RegExp.$5;
      }
    };
    
     //Mozilla  loadXML   
    Document.prototype.loadXML = function (sXml) {
    
      this.__initError__();
    
      this.__changeReadyState__(1);
    
      var oParser = new DOMParser();
      var oXmlDom = oParser.parseFromString(sXml, "text/xml");
 
      while (this.firstChild) {
          this.removeChild(this.firstChild);
      }

      for (var i=0; i < oXmlDom.childNodes.length; i++) {
        var oNewNode = this.importNode(oXmlDom.childNodes[i], true);
        this.appendChild(oNewNode);
      }
        
      //checkForErrors
      this.__checkForErrors__();
        
      //set readyState=4
      this.__changeReadyState__(4);
    };
    
    Document.prototype.__load__ = Document.prototype.load;

    Document.prototype.load = function (sURL) {
      this.__initError__();
      this.__changeReadyState__(1);
      this.__load__(sURL);
    };
    
    Node.prototype.__defineGetter__("xml", function () {
      var oSerializer = new XMLSerializer();
      return oSerializer.serializeToString(this, "text/xml");
    });
    
    Node.prototype.__defineGetter__("text",function(){ return this.textContent; });
    
    Node.prototype.selectSingleNode=function(sXPath){
      var oEvaluator = new XPathEvaluator();
      var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.FIRST_ORDERED_NODE_TYPE,null);
      if(null != oResult){
        return oResult.singleNodeValue;
      }
      return _xmlDom;
    }
        
    Node.prototype.selectNodes = function(sXPath){
      var oEvaluator = new XPathEvaluator();
      var oResult = oEvaluator.evaluate(sXPath,this,null, XPathResult.ORDERED_NODE_ITERATOR_TYPE,null);
      var aNodes = new Array();
      if(null != oResult){
        var oElement = oResult.iterateNext();
        while(oElement){
          aNodes.push(oElement);
          oElement = oResult.iterateNext();
        }
      }

      return aNodes;
    }

    return oXmlDom;        
        
  } else {
      throw new Error("Your browser doesn't support an XML DOM object.");
  }
}
//used for change diaply between some 'div'
//divname:  the div's name, note:in page, menu's id is 'menu'+divname+sequence
//divtotal: the tatol of the div
//divnow:   current div's id
//selectclass: the selected menu's class
function changeDivDisplay(divname, divtotal, divnow, selectclass){
	for(i=1; i<=divtotal; i++){
		var objmenu = document.getElementById("menu"+divname+i);//find the obj of menu
		var objcontent = document.getElementById("content"+divname+i);//find the obj of content		
		var objlink = document.getElementById("link"+divname+i);//find the obj of link,,,it can be null;
		if(objmenu && objcontent){//if 'objmenu' and 'objcontent' is not null
			if(i == divnow){//if i == divnow
				if(selectclass)
				  objmenu.className = selectclass;	//selected
				objcontent.style.display='';
				if(objlink)	//if have link
					objlink.style.display='';
			}else{
				objmenu.className = "";
				objcontent.style.display='none';
				if(objlink)
					objlink.style.display='none';
			}
		}
	}
}

//**************JavaScript Cookies ************************
//name:name of Cookie
//value:value of Cookie
//expires:expiring date
//path: cookie pass
//domain:cookie domain
//secure:cookie secure
function setCookie(name, value, expires, path, domain, secure){
	var strCookie = name + "=" + value;
	if (expires){
		var dtmNow = new Date();
		dtmNow.setTime(dtmNow.getTime() + expires*24*60*60*1000);
		strCookie += "; expires=" + dtmNow.toGMTString();
	}
	strCookie +=  (path) ? "; path=" + path : "";
	strCookie +=  (domain) ? "; domain=" + domain : "";
	strCookie +=  (secure) ? "; secure" : "";
	document.cookie = strCookie;
}
// name of Cookie
function getCookie(name){	
	var strCookies = document.cookie;
	var cookieName = name + "=";
	var intBegin, intEnd, strValue;
	intBegin = strCookies.indexOf(cookieName);
	if (intBegin == -1) return null;
	intEnd = strCookies.indexOf(";", intBegin);
	if (intEnd == -1) intEnd = strCookies.length;  // Cookie
	strValue = strCookies.substring(intBegin+cookieName.length,intEnd);
	return strValue;
}
//return the userid, if is log on
function getUserIdCookie(){
	return getCookie('UserId');
}
function getNicknameCookie(){
	return getCookie('Nickname');
}
//check is one click enable
//example:onload="if (isOneClickEnabled()) {doing();}"
//note: set isOneClickEnabledFlag=true where done
var isOneClickEnabledFlag=true;
function isOneClickEnabled() {
 if(isOneClickEnabledFlag){
  isOneClickEnabledFlag=false;
  return true;
 }
 else
  return false;
}